﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ERPStore.Extensions;
using ERPStore.Validators;

using global::FluentValidation;

using CloudSoft.Extensions;

namespace ERPStore.ModelValidators
{
	public class CorporateValidator : AbstractValidator<Models.Corporate>
	{
		public CorporateValidator()
		{
			RuleFor(m => m.Name)
				.NotNullOrTrimmedEmpty()
				.WithLocalizedName(() => Properties.Resources.ValidatorNotNullOrEmptyNameForCorporate);

			RuleFor(m => m.PhoneNumber)
				.PhoneNumber(m => m.DefaultAddress.Country)
				.When(m => m.DefaultAddress != null)
				.When(m => !m.PhoneNumber.IsNullOrTrimmedEmpty())
				.WithLocalizedName(() => Properties.Resources.ValidatorIsValidPhoneNumber);

			RuleFor(m => m.FaxNumber)
				.PhoneNumber(m => m.DefaultAddress.Country)
				.When(m => m.DefaultAddress != null)
				.When(m => !m.FaxNumber.IsNullOrTrimmedEmpty())
				.WithLocalizedName(() => Properties.Resources.ValidatorIsValidPhoneNumber);

			RuleFor(m => m.Email)
				.EmailAddress()
				.When(m => m.Email.IsNullOrTrimmedEmpty())
				.WithLocalizedName(() => Properties.Resources.ValidatorInvalidEmail);
		}
	}
}
